using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace bowlingkata.tests
{
    [TestFixture]
    public class test_BowlingGameExtensions
    {
        [Test]
        public void Calc_basic_scores()
        {
            var frames = new[] { new Frame(1,2,0), 
                                 new Frame(3,5,0)};
            frames = frames.Add_pins_in_frame().ToArray();
            Assert.AreEqual(new[] {3, 8 },
                            frames.Select(f => f.Score).ToArray());
        }


        [Test]
        public void Update_spare_scores()
        {
            var frames = new[] { new Frame(3,7, 10), 
                                 new Frame(1,9,10), 
                                 new Frame(2,5,7),
                                 new Frame(0,10,10),
                                 new Frame(3,4,7)};
            frames = frames.Add_bonus_for_spares().ToArray();
            Assert.AreEqual(new[] { 11, 12, 7, 13, 7 },
                            frames.Select(f => f.Score).ToArray());
        }


        [Test]
        public void Update_strike_scores()
        {
            var frames = new[] { new Frame(10,0,10), 
                                 new Frame(10,0,10), 
                                 new Frame(7,2,9)};
            frames = frames.Add_bonus_for_strikes().ToArray();
            Assert.AreEqual(new[] { 27, 19, 9 },
                            frames.Select(f => f.Score).ToArray());
        }


        [Test]
        public void Update_strike_score_in_frame10()
        {
            var frames = new[]
                             {
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(0,0,0),
                                 new Frame(10,0,10),
                                 new Frame(3,4,7)
                             };
            frames = frames.Add_bonus_for_strikes().ToArray();
            Assert.AreEqual(new[] {0,0,0,0,0,0,0,0,0,17,7 },
                            frames.Select(f => f.Score).ToArray());
        }
    }
}